using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace GoChat_for_Windows.Models
{
    [JsonConverter(typeof(StringEnumConverter))]
    public enum MessageType
    {
        [JsonProperty("TEXT")]
        Text,
        [JsonProperty("IMAGE")]
        Image,
        [JsonProperty("FILE")]
        File,
        [JsonProperty("VIDEO")]
        Video,
        [JsonProperty("AUDIO")]
        Audio,
        [JsonProperty("HEARTBEAT")]
        Heartbeat,
        [JsonProperty("HEARTBEAT_ACK")]
        HeartbeatAck,
        [JsonProperty("QUOTE")]
        Quote,
        [JsonProperty("RECALLED")]
        Recalled,
        [JsonProperty("READ_RECEIPT")]
        ReadReceipt
    }

    public partial class Message : ObservableObject
    {
        [ObservableProperty]
        private int id;

        [ObservableProperty]
        private int senderId;

        [ObservableProperty]
        private int receiverId;

        [ObservableProperty]
        private string content = string.Empty;

        [JsonProperty("type")]
        [ObservableProperty]
        private MessageType messageType;

        [JsonProperty("timestamp")]
        [ObservableProperty]
        private DateTime sendTime;

        [JsonIgnore]
        [ObservableProperty]
        private bool isSending;

        [JsonIgnore]
        [ObservableProperty]
        private bool sendFailed;

        [JsonIgnore]
        [ObservableProperty]
        private User? sender;

        [JsonIgnore]
        [ObservableProperty]
        private User? receiver;

        // 文件相关属性
        [JsonProperty("fileName")]
        [ObservableProperty]
        private string? fileName;

        [JsonProperty("fileSize")]
        [ObservableProperty]
        private long? fileSize;

        [JsonProperty("fileUrl")]
        [ObservableProperty]
        private string? fileUrl;

        [JsonIgnore]
        [ObservableProperty]
        private double? downloadProgress;

        // 引用消息相关属性
        [JsonProperty("quotedMessageId")]
        [ObservableProperty]
        private int? quotedMessageId;

        [JsonProperty("quotedContent")]
        [ObservableProperty]
        private string? quotedContent;

        [JsonProperty("quotedSenderName")]
        [ObservableProperty]
        private string? quotedSenderName;

        public override bool Equals(object? obj)
        {
            if (obj is Message other)
            {
                return Id == other.Id;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }
    }
} 